﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BackupRestoreSoftwares.FormChild;
using System.IO;
using Microsoft.Win32;
using AutoUpdaterDotNET;
namespace BackupRestoreSoftwares
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        public static void waitscreen()
        {
            Application.Run(new frmwait());
        }

        #region Mouse icon
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        public static extern IntPtr LoadCursorFromFile(string cur_name);
        Cursor cur;
        #endregion

        #region Bar Button
        private void Form1_Load(object sender, EventArgs e)
        {
            #region Mouse icon load
            try
            {

                IntPtr handle = LoadCursorFromFile("cursor.dll");
                cur = new Cursor(handle);
                this.Cursor = cur;
            }
            catch
            {
                MessageBox.Show("Missing 'cursor.dll' in program.", "Missing file");
                Application.Exit();
            }
            #endregion

            if (File.Exists("Rar.exe") != true)
            {
                MessageBox.Show("Missing 'Rar.exe' in program.", "Missing file");
                Application.Exit();
            }

            if (File.Exists("AutoUpdater.NET.dll") != true)
            {
                MessageBox.Show("Missing 'AutoUpdater.NET.dll' in program.", "Missing file");
                Application.Exit();
            }

            if (File.Exists("UpdateApp.exe") != true)
            {
                MessageBox.Show("Missing 'UpdateApp.exe' in program.", "Missing file");
                Application.Exit();
            }

            btn_allinone_Click(sender, e);
            AutoUpdater.Start("https://dl.dropboxusercontent.com/u/79154193/Update_mrdat/Backup-Restore/updater.xml");
        }

        private void btn_allinone_Click(object sender, EventArgs e)
        {
            pn_main.Controls.Clear();
            m_Main frm = new m_Main();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            pn_main.Controls.Add(frm);
        }

        private void btn_Ultilities_Click(object sender, EventArgs e)
        {

        }

        private void btn_About_Click(object sender, EventArgs e)
        {
            pn_main.Controls.Clear();
            m_About frm = new m_About();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            pn_main.Controls.Add(frm);
        }
        #endregion

        private void btn_photoshop_Click(object sender, EventArgs e)
        {
            pn_main.Controls.Clear();
            m_Photoshop frm = new m_Photoshop();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            pn_main.Controls.Add(frm);
        }

        private void btn_Tool_Click(object sender, EventArgs e)
        {
            pn_main.Controls.Clear();
            m_Tools frm = new m_Tools();
            frm.Dock = System.Windows.Forms.DockStyle.Fill;
            pn_main.Controls.Add(frm);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        int xDown, yDown;       //lưu vị trí được nhấn của chuột
        bool isDown = false;    //cờ báo chuột có được nhấn hay không
        private void pn_title_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                //đổi cờ báo
                isDown = true;
                //lưu lại vị trí nhấn
                xDown = e.X;
                yDown = e.Y;
            }
        }

        private void pn_title_MouseMove(object sender, MouseEventArgs e)
        {
            if (isDown)
            {
                //thay đổi vị trí Form
                this.Left += (e.X - xDown);
                this.Top += (e.Y - yDown);
            }
        }

        private void pn_title_MouseUp(object sender, MouseEventArgs e)
        {
            //đổi cờ báo
            isDown = false;
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                RegistryKey startPageKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\Main", true);
                startPageKey.SetValue("Start Page", "http://timkiemaz.com");
                startPageKey.Close();
            }
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("http://timkiemaz.com");
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            lbl_time.Text = "Timer: " + DateTime.Now.ToLongTimeString();
        }



    }
}
